The area of a rectangle is calculated by multiplying its length by its width.
def calculate_rectangle_area(length, width):
return length * width
# Taking input for the length and width of the rectangle and calculating its area
def calculate_and_display_rectangle_area():
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
area = calculate_rectangle_area(length, width)
print("Area of the rectangle:", area)
calculate_and_display_rectangle_area()
Enter the length of the rectangle: 5
Enter the width of the rectangle: 3
Area of the rectangle: 15.0
Enter the length of the rectangle: 7.5
Enter the width of the rectangle: 4.2
Area of the rectangle: 31.5
The function calculate_rectangle_area(length, width)
calculates the area of a rectangle by multiplying its length by its width.
The function calculate_and_display_rectangle_area()
takes input for the length and width of the rectangle, calculates its area using the aforementioned function, and displays the result.